package com.jeesite.modules.front.web;


import com.jeesite.common.entity.Page;
import com.jeesite.modules.HttpRequestDeviceUtils;
import com.jeesite.modules.site.entity.SiteArticle;
import com.jeesite.modules.site.entity.SiteFriendlink;
import com.jeesite.modules.site.service.SiteArticleService;
import com.jeesite.modules.site.service.SiteFriendlinkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping(value = "${frontPath}/article")
public class ArticleController {
    @Autowired
    private SiteFriendlinkService siteFriendlinkService;
    @Autowired
    private SiteArticleService siteArticleService;


    @RequestMapping(value = {"show", ""})
    public  String show(String id,Model model,HttpServletRequest request){
        SiteFriendlink siteFriendlink = new SiteFriendlink();
        siteFriendlink.setPos(1);
        Page<SiteFriendlink> page = siteFriendlinkService.findPage(new Page<SiteFriendlink>(),siteFriendlink);
        model.addAttribute("scroll",page.getList());

        SiteArticle siteArticle = siteArticleService.get(id);
        model.addAttribute("article",siteArticle);
        if(HttpRequestDeviceUtils.isMobileDevice(request)){

            return "modules/front/waparticle";
        }
        else {
            return "modules/front/columnarticle";
        }

    }
    @RequestMapping(value = "tool")
    public String tool(Model model) {
        SiteFriendlink siteFriendlink = new SiteFriendlink();
        siteFriendlink.setPos(1);
        Page<SiteFriendlink> page = siteFriendlinkService.findPage(new Page<SiteFriendlink>(),siteFriendlink);
        model.addAttribute("scroll",page.getList());
        return "modules/front/tool";
    }
    @RequestMapping(value = "tool1")
    public String tool1(Model model) {
        return "modules/front/1";
    }
    @RequestMapping(value = "tool2")
    public String tool2(Model model) {
        return "modules/front/2";
    }
    @RequestMapping(value = "tool3")
    public String tool3(Model model) {
        return "modules/front/3";
    }
    @RequestMapping(value = "tool4")
    public String tool4(Model model) {
        return "modules/front/4";
    }
    @RequestMapping(value = "tool5")
    public String tool5(Model model) {
        return "modules/front/5";
    }
}
